# -*- coding: utf-8 -*-
# 2016 Elico Corp (https://www.elico-corp.com).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models
import addons.decimal_precision as dp

class PurchaseOrderLine(models.Model):
    _inherit = 'purchase.order.line'
    '''根据总计，倒算单价'''
    _order = 'order_id,name,sequence, id'

    # price_unit = fields.Float(string='Unit Price', required=True, digits=dp.get_precision('Product Price'))
    price_total = fields.Monetary(compute='_compute_amount', string='Total',
                                  readonly=False, store=True)  # 设置为可写
    @api.onchange('price_total')
    @api.multi
    def _compute_price(self):
        for line in self:
            if line.product_qty:
                line.price_unit=line.price_total/line.product_qty
            else:
                line.product_qty=1
                line.price_unit=line.price_total

class PurchaseOrder(models.Model):
    _inherit = 'purchase.order'

    pur_document_datas = fields.Binary(string='附件', attachment=True)
    pur_document_fname = fields.Char('附件名', index=True)
